package org.michael.u.brg.i18n.litz;

/**
 * Backslashed Unicode.
 */
public class LitzUnicode extends LitzXlator {

    public final String getVisual(String encoding) {
        int len = encoding.length();
        StringBuilder retVal = new StringBuilder(len * 6);
        for (int i = 0; i < len; i += 6) {
            char c = (char) Integer.parseInt(encoding.substring(i + 2, i + 6), 16);
            retVal.append(c);
        }

        return retVal.toString();
    }

    public final String getName() {
        return "Unicode Backslash";
    }

    public final String getEncoding(String visual) {
        int len = visual.length();
        StringBuilder retVal = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            String hex = Integer.toHexString(visual.charAt(i));
            retVal.append("\\u");
            for (int j = 0; j < 4 - hex.length(); j++)
                retVal.append('0');

            retVal.append(hex.toUpperCase());
        }

        return retVal.toString();
    }
}
